package com.ffs.game.scene.obj.ai.fsm.monster;

import com.ffs.game.scene.GameScene;
import com.ffs.game.scene.obj.Monster;
import com.ffs.game.scene.obj.ai.AIData;
import com.ffs.game.scene.obj.ai.MonsterAIFactory;
import com.ffs.game.scene.obj.ai.MonsterState;
import com.ffs.game.scene.obj.ai.fsm.AbstractFSMState;

/**
 * 怪物巡逻状态
 *
 * @author ffs80
 */
public class MonsterActiveState extends AbstractFSMState<MonsterState, Monster> {

    public MonsterActiveState(MonsterState state, Monster monster) {
        super(state, monster);
    }

    @Override
    public void enter(GameScene screen) {
        MonsterAIFactory.findAI(monster.getAiType()).activeEnter(screen, monster);
    }

    @Override
    public void exit(GameScene screen) {
        MonsterAIFactory.findAI(monster.getAiType()).activeExit(screen, monster);
    }

    @Override
    public void update(GameScene screen, int delta) {
        MonsterAIFactory.findAI(monster.getAiType()).activeUpdate(screen, monster, delta);
        monster.setCurFrame(findCurFrame());
    }

    @Override
    public MonsterState checkTransfer(GameScene screen) {
        AIData aiData = monster.getMonsterMachine().getAiData();
        if (aiData.getAttackTarget() >= 0) {
            return MonsterState.fight;
        }

        if (monster.isDead()) {
            return MonsterState.die;
        }

        return MonsterState.active;
    }
}
